#include "firstwindow.h"
#include "ui_firstwindow.h"

#include <QApplication>
#include <QWidget>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QDebug>
#include <QCompleter>
#include <QListView>
#include <QMap>
#include <QListWidgetItem>
#include <mainwindow.h>
#include <QSizePolicy>
#include "main.h"


firstwindow::firstwindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::firstwindow)
{
    ui->setupUi(this);

    QVector<Friend> f_list = db.GetAllFriends();
    for(auto f:f_list){
        user_list.push_back(user(QString::number(f.id),f.name,f.ip));
    }

    //根据传入列表产生页面内容
//    mainwindow * page_message = new mainwindow;
//    mainwindow * page_friends = new mainwindow;
//    mainwindow * page_groups = new mainwindow;
//    mainwindow * page_research = new mainwindow;

    //页面添加到切换区
//    qDebug() << "1页面索引: " <<ui->stack->addWidget(page_message->show_message());
//    qDebug() << "2页面索引: " <<ui->stack->addWidget(page_friends->show_friends());
//    qDebug() << "3页面索引: " <<ui->stack->addWidget(page_groups->show_groups());
//    qDebug() << "4页面索引: " <<ui->stack->addWidget(page_research->show_result());
    qDebug() << "页面索引总数: " << ui->stack->count();
    //绑定页面和按键
    connect(ui->abutton,&QPushButton::clicked,this,&firstwindow::switchPage);
    connect(ui->bbutton,&QPushButton::clicked,this,&firstwindow::switchPage);
    connect(ui->cbutton,&QPushButton::clicked,this,&firstwindow::switchPage);
    connect(ui->dbutton,&QPushButton::clicked,this,&firstwindow::switchPage);


    //自定数据库
    //QStringList word_list;
   // word_list<<"Java"<<"C++"<<"C#"<<"PHP"<<"Perl"<<"Python"<<"Delphi"<<"Ruby";
    //模糊匹配（
    //QCompleter *NewFind = new QCompleter(word_list);
    //ui->comboBox->setCompleter(NewFind);

}

firstwindow::~firstwindow()
{
    delete ui;
}



void firstwindow::on_abutton_clicked()
{
    qDebug() << "按钮1信号绑定成功";
}

void firstwindow::on_bbutton_clicked()
{
    qDebug() << "按钮2信号绑定成功";
}

void firstwindow::on_cbutton_clicked()
{
    qDebug() << "按钮3信号绑定成功";
}

void firstwindow::on_dbutton_clicked()
{
    qDebug() << "按钮搜索信号绑定成功";
}

void firstwindow::add_message(user& newuser){
    qDebug()<<"dd1";
    page_message->add_message(newuser);
}


void firstwindow::switchPage(){
    QPushButton *button = qobject_cast<QPushButton*>(sender());
    if(button==ui->abutton)
        ui->stack->setCurrentIndex(0);
    else if(button==ui->bbutton)
        ui->stack->setCurrentIndex(1);
    else if(button==ui->cbutton)
        ui->stack->setCurrentIndex(2);
    else if(button==ui->dbutton)
        ui->stack->setCurrentIndex(3);
}
